home *** CD-ROM | disk | FTP | other *** search
/ Ham Radio 2000 #2 / Ham Radio 2000 - Volume 2.iso / HAMV2 / TCP_IP / TNOS230S / PROC.H < prev    next >
Encoding:
C/C++ Source or Header  |  1997-08-18  |  4.7 KB  |  153 lines

  1. #ifndef    _PROC_H
  2. #define    _PROC_H
  3.  
  4. #ifndef _SETJMP_H
  5. #include <setjmp.h>
  6. #endif
  7.  
  8. #ifndef _MBUF_H
  9. #include "mbuf.h"
  10. #endif
  11.  
  12. #ifndef    _TIMER_H
  13. #include "timer.h"
  14. #endif
  15.  
  16. #if !defined(_SESSION_H) && !defined(_HARDWARE_H) && !defined(_GLOBAL_H)
  17. struct session;            /* forward declaration */
  18. #endif
  19.  
  20. #define    OUTBUFSIZE    512    /* Size to be malloc'ed for outbuf */
  21.  
  22.  
  23. /* Kernel process control block */
  24. #define    PHASH    16        /* Number of wait table hash chains */
  25. struct proc {
  26.     short magic1;        /* for sanity checking */
  27. #define PROC_MAGIC1    0x7388
  28.     struct proc *prev;    /* Process table pointers */
  29.     struct proc *next;    
  30.  
  31.     jmp_buf env;        /* Process register state */
  32.     char i_state;        /* Process interrupt state */
  33.  
  34.     unsigned short state;
  35. #define    READY    0
  36. #define    WAITING    1
  37. #define    SUSPEND    2
  38.     volatile void *event;    /* Wait event */
  39.     int16 *stack;        /* Process stack */
  40.     unsigned stksize;    /* Size of same */
  41.     char *name;        /* Arbitrary user-assigned name */
  42.     int retval;        /* Return value from next kwait() */
  43.     struct timer alarm;    /* Alarm clock timer */
  44.     struct mbuf *outbuf;    /* Terminal output buffer */
  45.     int input;        /* standard input socket */
  46.     int output;        /* standard output socket */
  47.     int iarg;        /* Copy of iarg */
  48.     void *parg1;        /* Copy of parg1 */
  49.     void *parg2;        /* Copy of parg2 */
  50.     int freeargs;        /* Free args on termination if set */
  51. #ifdef UNIX
  52.     struct session *session; /* for session manager - sigh */
  53. #endif
  54. /* #ifdef USE_SETSTACK */
  55.                 /* Scratch pointer for process function */
  56.     void (*func)(int, void*, void*);
  57. /* #endif */
  58. #ifdef SCRIPTING
  59.     char *gotolabel;    /* for use w/Command session rmt sysop goto cmd */
  60.     int16 condfalse;    /* used by if/while commands */
  61. #endif
  62.     int ptype;        /* process type */
  63. #define    PTYPE_NORMAL    0    /* regular processes */
  64. #define PTYPE_DAEMON    1    /* one of the daemons in the Daemon list */
  65. #define PTYPE_SERVER    2    /* a server process */
  66. #define PTYPE_IO    3    /* I/O tx/rx process */
  67.  
  68.     short magic2;        /* for sanity checking */
  69. #define PROC_MAGIC2    0x7373
  70. };
  71. #define NULLPROC (struct proc *)0
  72.  
  73. extern struct proc *Waittab[];    /* Head of wait list */
  74. extern struct proc *Rdytab;    /* Head of ready list */
  75. extern struct proc *Curproc;    /* Currently running process */
  76. extern struct proc *Susptab;    /* Suspended processes */
  77.  
  78.  
  79. #define    SIGQSIZE    300    /* Entries in ksignal queue */
  80. #define RESTART_COUNT    20    /* # of SIGSEGV recoveries to attempt */
  81.  
  82.  
  83. struct sigentry {
  84.     volatile void *event;
  85.     int n;
  86. };
  87. struct ksig {
  88.     struct sigentry entry[SIGQSIZE];
  89.     struct sigentry *wp;
  90.     struct sigentry *rp;
  91.     volatile int nentries;    /* modified both by interrupts and main */
  92.     int maxentries;
  93.     int32 duksigs;
  94.     int32 lostsigs;
  95.     uint32 ksigs;        /* Count of ksignal calls */
  96.     uint32 ksigwakes;    /* Processes woken */
  97.     uint32 ksignops;    /* ksignal calls that didn't wake anything */
  98.     uint32 ksigsqueued;    /* ksignal calls queued with ints off */
  99.     uint32 kwaits;        /* Count of kwait calls */
  100.     uint32 kwaitnops;    /* kwait calls that didn't block */
  101.     uint32 kwaitints;    /* kwait calls from interrupt context (error) */
  102. #ifdef UNIX
  103.     uint32 krestarts;    /* # times daemon processes restarted from SIGSEGV */
  104.     uint32 kresumes;    /* # times daemon resumed from SIGSEGV */
  105.     uint32 kfreesegvs;    /* # times a free() ignored a SIGSEGV */
  106. #endif
  107. };
  108. extern struct ksig Ksig;
  109.  
  110. /* Prepare for an exception signal and return 0. If after this macro
  111.  * is executed any other process executes alert(pp,val), this will
  112.  * invoke the exception and cause this macro to return a second time,
  113.  * but with the return value 1. This cannot be a function since the stack
  114.  * frame current at the time setjmp is called must still be current
  115.  * at the time the signal is taken. Note use of comma operators to return
  116.  * the value of setjmp as the overall macro expression value.
  117.  */
  118. #define    SETSIG(val)    (Curproc->flags.sset=1,\
  119.     Curproc->signo = (val),setjmp(Curproc->sig))
  120.  
  121.  
  122.  
  123. /* In  kernel.c: */
  124. void alert (struct proc *pp,int val);
  125. void chname (struct proc *pp,const char *newname);
  126. void killproc (struct proc *pp);
  127. void killself (void);
  128. struct proc *mainproc (const char *name);
  129. struct proc *newproc (const char *name,unsigned int stksize,
  130.     void (*pc) (int,void *,void *),
  131.     int iarg,void *parg1,void *parg2,int freeargs);
  132. int ksignal (volatile void *event, int n);
  133. int kwait (volatile void *event);
  134. void resume (struct proc *pp);
  135. void suspend (struct proc *pp);
  136.  
  137. /* In ksubr.c: */
  138. void kinit (void);
  139. unsigned phash (volatile void *event);
  140. void psetup (struct proc *pp);
  141. #ifdef    AMIGA
  142. void init_psetup (struct proc *pp);
  143. #endif
  144.  
  145. /* Stack background fill value for high water mark checking */
  146. #define    STACKPAT    0x55aa
  147.  
  148. /* Value stashed in location 0 to detect null pointer dereferences */
  149. #define    NULLPAT        0xdead
  150.  
  151. #endif    /* _PROC_H */
  152.  
  153.